package it.polito.connectedcar.general.network;

import java.net.SocketException;

/**
 * This class represents a factory providing sockets for a real environment. See
 * {@link SimpleDatagramSocket} for more details on the socket used in a real
 * scenario
 * 
 * @author Nicola Aresta
 * 
 */
public class SimpleNetworkConnectorFactory implements NetworkConnectorFactory {

	private int port;
	private static final int STANDARD_PORT = 9000;

	public SimpleNetworkConnectorFactory() {
		String networkPort = System.getProperty("networkPort");
		if (networkPort != null) {
			try {
				port = Integer.valueOf(networkPort);
			} catch (NumberFormatException ne) {
				port = STANDARD_PORT;
			}

		} else
			port = STANDARD_PORT;
	}

	@Override
	public synchronized ConnectedCarSocket getSocket() throws SocketException {
		return new SimpleDatagramSocket(port);
	}
}
